<style>
    .li_a_cur{
        background:#123;
    }
    .treeview-menu{
        padding-left: 0px;
    }
</style>
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
      <!-- Sidebar user panel (optional) -->
      <div class="user-panel">
        <div class="pull-left image">
          <img src="{{ asset("/image/admin_pic.jpg") }}" class="img-circle" alt="User Image">
        </div>
        <div class="pull-left info">
          <p>{{ Auth::user()->name }}</p>
          <!-- Status -->
          <a href="#"><i class="fa fa-circle text-success"></i> 在线</a>
        </div>
      </div>

       <input type="hidden" id="currentUrl" value=" {{ $_SERVER['REQUEST_URI'] }}">
      <!-- Sidebar Menu -->
      <ul class="sidebar-menu" data-widget="tree">
        <li class="header">{{ trans('message.menu') }}</li>
          <li class="mainhead active">
              <a href="{{ url('home') }}">
                  <i class="fa fa-dashboard"></i> <span>首页</span>
              </a>
          </li>
          @if($itemS = menu('admin'))
              @if(Auth::user())
                  @foreach($itemS as $k=>$item)
                      {{--去除首页,单独显示--}}
                      @if($item['id'] !=1)

                      @if(in_array($item['id'],menu_permission(Auth::user()->id)))
                          @if($item['parent_id']== $item['id'])
                              <li class="treeview menu-open ">
                                  <a href="#">
                                      <i class="fa {{$item['icon']}}"></i>
                                      <span>{{$item['title']}}</span>
                                      <i class="fa fa-angle-left pull-right"></i>
                                  </a>
                                  <ul class="treeview-menu" style="display: block;">
                                      @if($itemO = menu('admin',$item['parent_id']))
                                          @foreach($itemO as $key=>$value)
                                              @if(in_array($value['id'],menu_permission(Auth::user()->id)))
                                                  @if($key !=0)
                                                      <li id="click_{{ $value['id'] }}"><a href="{{ url($value['uri']) }}"><i class="fa {{$value['icon']}}"></i>{{$value['title']}}</a></li>
                                                  @endif
                                              @endif
                                          @endforeach
                                      @endif
                                  </ul>
                              </li>
                          @endif
                      @endif

                      @endif
                  @endforeach
              @endif
          @endif
      </ul>
      <!-- /.sidebar-menu -->
    </section>
    <!-- /.sidebar -->
  </aside>
<script src="{{ asset ("/AdminLTE/bower_components/jquery/dist/jquery.min.js") }}"></script>
{{--<script src="{{ asset ("js/jquery-1.8.3.min.js") }}"></script>--}}
{{--<script src="{{ asset ("/js/jquery.cookie.js") }}"></script>--}}
<script type="text/javascript">
    var keyword = 'public/';
    var cUrl = $('#currentUrl').val();
    var Location = cUrl.indexOf("public/") + keyword.length;
    var currentUrl = cUrl.substr(Location);
//    alert(currentUrl);

        $(".sidebar-menu li a").click(function(){
//            var clen = document.cookie.length;
//            alert(clen);
            var index = $(this).attr("href");
            var lid = $(this).parent().attr('id');
            document.cookie = index + '@' + lid;
//            alert(document.cookie);
        });

    var clickUrlCook=document.cookie.split(";")[0];
    var url = clickUrlCook.substr(0,clickUrlCook.indexOf("@"));
    var classId = clickUrlCook.substr(clickUrlCook.indexOf("@")+1);
    console.log(url);
    console.log(classId);
    var start = url.indexOf("public/") + keyword.length;
    var clickUrl = url.substr(start);
    console.log(currentUrl);


    if(currentUrl == clickUrl) {
        console.log('==');
        $('.sidebar-menu').find('.mainhead').removeClass("active");
        $("#"+classId).find('a').addClass("li_a_cur");
//            console.log( $("#"+classId).parent().parent());
        $("#"+classId).parent().parent().addClass("active");
    } else {
        $("#"+classId).find('a').removeClass("li_a_cur");
        $("#"+classId).parent().parent().removeClass("active");
    }


</script>



